<template>
  <view v-if="headInfo.length > 0">
    <uni-table border stripe :emptyText="getTranslate(0)" >
      <!-- 表头行 -->
      <uni-tr>
        <uni-th align="center" v-for="(h, i) in headInfo" :key="i"> {{ h.name }}</uni-th>
      </uni-tr>
      <!-- 表格数据行 -->
      <uni-tr v-for="(l, i) in lineInfo" :key="i">
        <uni-th align="center" v-for="(_l, _i) in l" :key="_i" >
          <view v-if="isNeedReUpload(_i, _l.name)">
            <u-button type="error" :text="getTranslate(1)" @click="reUpload(i)"></u-button>
          </view>
          <view v-else>{{ getShortText(_l.name, _i) }}</view>
        </uni-th>
      </uni-tr>
    </uni-table>
  </view>
</template>

<script>
import language from "../../api/language";
import statusJudge from "../../utils/monitor/statusJudge";
import appConfig from "../../api/appConfig";

export default {
  name: "segTable",
  props: {
    headInfo: {
      default: [],
      type: Array
    },
    lineInfo: {
      default: [],
      type: Array
    },
    errorMonitor: {
      default: [],
      type: Array
    }
  },
  mixins: [statusJudge],
  methods: {
    getShortText(name, index){
      if(this.judge(appConfig.calMode.mobileNoLeft) && index === 0){
        return name.toString().substr(0, 20) + '...'
      }
      return name
    },
    getWidth(){
      return 100 / this.headInfo.length + '%'
    },
    getTranslate(posIndex){
      let langDict = language.getTranslate(language.segTable)
      if (posIndex === 0){
        return langDict.noData
      }else if(posIndex === 1){
        return langDict.reUpload
      }
    },
    isNeedReUpload(index, info){
      if(index !== 1) return false
      if(info.indexOf('error') !== -1) return true
    },
    reUpload(key){
      this.$emit('reUpload', this.errorMonitor[key])
    }
  }
}
</script>

<style scoped>

</style>
